package main;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.geom.NoninvertibleTransformException;
import java.util.ArrayList;


public class TimeSignature {

	
	private double bpm;
	private double oneBeat;
	
	/**
	 * Creates a time signature
	 * @param b beats per measure
	 * @param o what is one beat
	 */
	public TimeSignature(int b, int o){
		bpm = b;
		oneBeat = o;
		}
	
	public TimeSignature(String t){
		bpm =  Double.parseDouble(t.substring(0, t.indexOf('/')));
		oneBeat =  Double.parseDouble(t.substring(t.indexOf('/')+1));

	}
	
	/**
	 * paints the time signature
	 * @param g Graphics context
	 * @param hOff cursor position
	 * @param parent parent component
	 * @return new cursor position
	 */
	public int draw(Graphics2D g, int hOff, Score parent){
		Font font = g.getFont();
		ArrayList<Integer> spacing = parent.getSpacingList();
		int halfStave = Score.TOTAL_STAFF_SIZE/2;
		Font timeFont = new Font(Font.SERIF, Font.BOLD,halfStave+5);
		g.setFont(timeFont);
		g.drawString((int)bpm+"", hOff, halfStave-3);
		g.drawString((int)oneBeat+"", hOff, spacing.get(spacing.size()-1)+Score.NOTE_HEAD_SIZE/2-3);
		g.setFont(font);
		return hOff+30; 
	}

	public double getBpm() {
		return bpm;
	}

	public void setBpm(int bpm) {
		this.bpm = bpm;
	}

	public double getOneBeat() {
		return oneBeat;
	}

	public void setOneBeat(int oneBeat) {
		this.oneBeat = oneBeat;
	}
	
	public String toString(){
		return (int)bpm + "/" + (int)oneBeat;
	}
}
